package lec02.am;

public class StringDemo2 {
	static int SIZE=100000;
	
public static void main(String[] args) {
	testString();
	testCharArray();
	testStringBuffer();
}

private static void testString() {
	long startTime=System.nanoTime();
	String p="";
	for(int i=0;i<SIZE;i++)
		p+='a';
	long endTime=System.nanoTime();
	double elapse=(endTime-startTime)*1E-9;
	System.out.println(String.format("%.6f",elapse));
	
	
}
private static void testCharArray() {
	long startTime=System.nanoTime();
	char cs[]=new char[SIZE];
	for(int i=0;i<SIZE;i++)
		cs[i]='a';
	long endTime=System.nanoTime();
	double elapse=(endTime-startTime)*1E-9;
	System.out.println(String.format("%.6f",elapse));
	
	
}
private static void testStringBuffer() {
	long startTime=System.nanoTime();
	//StringBuffer sb=new StringBuffer();
	StringBuilder sb=new StringBuilder();
	for(int i=0;i<SIZE;i++)
		sb.append('a');
	long endTime=System.nanoTime();
	double elapse=(endTime-startTime)*1E-9;
	System.out.println(String.format("%.6f",elapse));
	
	
}
}
